<template>
  <div style="height:100%">
    <breadcrumb :breadList="breadList" :name="name" style="margin-bottom: 12px;" v-if="!statusCode">
      <div class="handle-box" slot="handleContent">
        <!-- <div class="handle-btn">
          <a-button class="common-btn" >关联用户</a-button>
        </div> -->
        <!-- <div class="handle-btn">
          <a-button class="common-btn" @click="submitProMessage">提交</a-button>
        </div>
        <div class="handle-btn">
          <a-button @click="cancel" class="common-btn">取消</a-button>
        </div> -->
        <div class="handle-btn" v-if="currentType === 'create'">
          <a-button class="common-btn" @click="connectUser">关联用户</a-button>
        </div>
        <div class="handle-btn" v-if="currentType === 'modify'">
          <a-button class="common-btn" @click="updateUser">修改用户</a-button>
        </div>
      </div>
    </breadcrumb>
    <a-card class="card" v-if="currentType === 'approve'">
      <a-row :gutter="16">
        <a-col :lg="24" :md="12" :sm="24">
          <a-form-item label="审批结论" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
            <a-radio-group v-decorator="['queryParam.approveRes', {rules: [{required: false, message: ''}]}]">
              <a-radio :value="1">A</a-radio>
              <a-radio :value="2">B</a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="16">
        <a-col :lg="24" :md="12" :sm="24">
          <a-form-item label="审批意见" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 20}, sm: {span: 17} }">
            <a-textarea v-decorator="['queryParam.approveAdv', {rules: [{required: false, message: ''}]}]" rows="3" placeholder="审批意见" style="width: 800px;"/>
          </a-form-item>
        </a-col>
      </a-row>
    </a-card>
    <a-card class="spec-card" :title="code" :bordered="false" v-if="!statusCode">
      <span class="card-title-btn-box" v-if="$route.query.type === 'detail'">
        <a-button class="common-btn card-title-btn" @click="toSeeCount">查看关联用户</a-button>
      </span>
    </a-card>
    <a-card class="card" title="项目基本信息" :bordered="false">
      <a-form :form="form">
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="项目名称" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.proName', {initialValue: this.currentPro.proName, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="责任单位" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.dutyCompany', {initialValue: currentPro.dutyCompany, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="联系人" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input :disabled="disabled" v-decorator="['queryParam.personName', {initialValue: currentPro.proPerson, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="联系电话" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.personTel', {initialValue: currentPro.proTel, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="20" :md="12" :sm="24">
            <div class="spec-row">
              <a-form-item class="spec-item" label="行政区域" :labelCol="{lg: {span: 4}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
                <div style="display:flex;">
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.provice', {initialValue: '山西省', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="山西省">山西省</a-select-option>
                      <a-select-option value="山东省">山东省</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.municipal', {initialValue: '太原市', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="市">市</a-select-option>
                      <a-select-option value="太原市">太原市</a-select-option>
                      <a-select-option value="未知市">未知市</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.county', {initialValue: '小店区', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="县（区）">县（区）</a-select-option>
                      <a-select-option value="小店区">小店区</a-select-option>
                      <a-select-option value="未知区">未知区</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.village', {initialValue: '小店乡', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="乡（镇/街道）">乡（镇/街道）</a-select-option>
                      <a-select-option value="小店乡">小店乡</a-select-option>
                    </a-select>
                  </a-form-item>
                  <a-form-item>
                    <a-select :disabled="disabled" v-decorator="['queryParam.burg', {initialValue: '小店村', rules: [{required: false, message: ''}]}]" style="width: 145px;">
                      <a-select-option value="村（社区）">村（社区）</a-select-option>
                      <a-select-option value="村">村</a-select-option>
                    </a-select>
                  </a-form-item>
                </div>
              </a-form-item>
            </div>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="计划年度" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-select :disabled="disabled" v-decorator="['queryParam.year', {initialValue: 1, rules: [{required: false, message: ''}]}]" style="width: 270px;">
                <a-select-option :value="1">2017年以前</a-select-option>
                <a-select-option :value="2">2017</a-select-option>
                <a-select-option :value="3">2018</a-select-option>
                <a-select-option :value="4">2019</a-select-option>
                <a-select-option :value="5">2020</a-select-option>
                <a-select-option :value="6">2021</a-select-option>
                <a-select-option :value="7">2022</a-select-option>
                <a-select-option :value="8">2023</a-select-option>
                <a-select-option :value="9">2024</a-select-option>
                <a-select-option :value="10">2025</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="改造路径" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-select :disabled="disabled" v-decorator="['queryParam.proType', {initialValue: '煤改气',rules: [{required: false, message: ''}]}]" style="width: 270px;">
                <a-select-option value="煤改气">煤改气</a-select-option>
                <a-select-option value="煤改电">煤改电</a-select-option>
                <a-select-option value="集中供热">集中供热</a-select-option>
                <a-select-option value="其他">其他</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="总用户数" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.totalCount', {initialValue: currentPro.totalCount, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="建筑面积（m²）" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.totalEara', {initialValue: currentPro.totalEara, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="设备总数（台）" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input-number :disabled="disabled" v-decorator="['queryParam.totalCountEquipment', {initialValue: currentPro.totalCountEquipment, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="计划开工时间" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input placeholder="年/月/日" :disabled="disabled" v-decorator="['queryParam.proStart', {initialValue: currentPro.proStart, rules: [{required: false, message: ''}]}]" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="计划完工时间" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <a-input placeholder="年/月/日" :disabled="disabled" v-decorator="['queryParam.proEnd', {initialValue: currentPro.proEnd, rules: [{required: false, message: ''}]}]" style="width: 270px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :sm="24">
            <a-form-item label="项目描述/备注" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 17}, sm: {span: 17} }">
              <a-textarea rows="1" :disabled="disabled" v-decorator="['queryParam.remark', {initialValue: currentPro.remark, rules: [{required: false, message: ''}]}]" placeholder="" style="width: 270px;"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
    <a-card class="card" title="资料上传" :bordered="false">
      <a-form>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="招投标资料" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:600px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="施工资料" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="验收资料" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="16">
          <a-col :lg="24" :md="12" :sm="24">
            <a-form-item label="其他资料" :labelCol="{lg: {span: 3}, sm: {span: 7}}" :wrapperCol="{lg: {span: 12}, sm: {span: 17} }">
              <div style="width:200px;display:flex;" >
                <a-upload
                  v-if="isShow"
                  name="file"
                  :multiple="true"
                  action="//jsonplaceholder.typicode.com/posts/"
                  :headers="headers"
                  @change="handleChange">
                  <a>
                    上传
                  </a>
                </a-upload>
                <a style="margin:0 20px" @click="downLoad">下载</a>
                <a>查看</a>
              </div>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="!statusCode">
          <div style="text-align:center;">
            <a-button class="common-btn" @click="submitProMessage">确定</a-button>
            <a-button @click="cancel" class="common-btn" style="margin-left:10px;">取消</a-button>
          </div>
        </a-row>
      </a-form>
    </a-card>
  </div>
</template>

<script>
import GlobalHeader from '@/components/GlobalHeader'
import Breadcrumb from '@/components/tools/Breadcrumb'
import Cascader from 'ant-design-vue/lib/cascader'
export default {
  name: 'AddProjects',
  components: {
    GlobalHeader,
    Breadcrumb,
    'a-cascader': Cascader
  },
  props: {
    type: {
      type: String,
      default: ''
    },
    statusCode: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      name: '',
      breadList: [],
      code: '',
      disabled: false,
      isShow: true,
      queryParam: {},
      form: this.$form.createForm(this),
      currentType: '', // 当前页面所属
      currentPro: {}, // 当前产品详情
      headers: {
        authorization: 'authorization-text'
      }
    }
  },
  created () {
    console.log('组建传值', this.type, this.statusCode)
    this.currentType = this.$route.query.type
    this.currentPro = JSON.parse(this.$route.query.proDetails)
    this.getBreadCrumb()
    this.code = (this.$route.query.type !== 'create' && this.$route.query.type !== 'update') ? '项目编号：' + this.currentPro.proCode : '项目编号：' + 'SX_TY_001'
    console.log('当前详情', this.currentType, this.currentPro)
    if (this.$route.query.type === 'approve' || (this.type && this.type === 'detail')) {
      this.disabled = true
      this.isShow = false
    } else {
      this.disabled = false
      this.isShow = true
    }
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
      switch (this.$route.query.type) {
        case 'detail':
          this.breadList[2].meta.title = '项目详情'
          break
        case 'modify':
          this.breadList[2].meta.title = '编辑项目'
          break
        case 'approve':
          this.breadList[2].meta.title = '项目详情'
          break
        default:
          this.breadList[2].meta.title = '添加项目'
          break
      }
    },
    onChange (value) {
      console.log(value)
    },
    handleChange (info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        this.$message.success(`${info.file.name} 上传成功`)
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name} 上传失败.`)
      }
    },
    cancel () {
      const that = this
      this.$confirm({
        title: '是否确定取消，取消后数据将清空',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '已取消'
          })
        }
      })
    },
    submitProMessage () {
      const that = this
      this.$confirm({
        title: '确认提交吗',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '已提交'
          })
        }
      })
    },
    connectUser () {
      this.$warning({
        title: '请输入正确的用户信息'
      })
    },
    updateUser () {
      const that = this
      this.$confirm({
        title: '用户一旦更改立即生效，请确认是否继续更改用户',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '已提交'
          })
        }
      })
    },
    toSeeCount () {
      this.$warning({
        title: '当前无关联用户'
      })
    },
    downLoad () {
      this.$success({
        title: '下载成功，请本地打开查看'
      })
    },
    addEquipmentDetails () {
      this.$router.push({
        name: 'addEquipmentDetails'
      })
    }
  }
}
</script>

<style lang="less" scoped>
.spec-row {
  margin-left: -16px;
}
.spec-item {
  margin-bottom: 0px;
}
.spec-card {
  height: 56px;
}
</style>
